package com.ssy.lingxi.logistics.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.api.dto.request.CommonIdRequest;
import com.ssy.lingxi.logistics.model.request.ShipperAddressRequest;
import com.ssy.lingxi.logistics.model.request.StoreShipperAddressListRequest;
import com.ssy.lingxi.logistics.model.response.ShipperAddressListResponse;
import com.ssy.lingxi.logistics.model.response.ShipperAddressResponse;
import com.ssy.lingxi.logistics.model.response.StoreShipperAddressListResponse;
import com.ssy.lingxi.logistics.service.IShipperAddressService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 物流能力 - 物流管理 - 发货地址管理
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/shipperAddress")
public class ShipperAddressController extends BaseController {

    @Resource
    private IShipperAddressService shipperAddressService;

    /**
     * 发货地址分页列表
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<ShipperAddressListResponse>> pageShipperAddress(PageVO request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return shipperAddressService.pageShipperAddress(request, sysUser);
    }

    /**
     * 发货地址查询
     * @param id 主键id
     * @return 返回结果
     */
    @GetMapping(value = "/get")
    public Wrapper<ShipperAddressResponse> getShipperAddress(@RequestParam(name = "id") Long id) {
        return shipperAddressService.getShipperAddress(id);
    }

    /**
     * 发货地址添加
     *
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/add")
    public Wrapper<ShipperAddressResponse> addShipperAddress(@RequestBody @Validated(ShipperAddressRequest.Add.class) ShipperAddressRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return shipperAddressService.addShipperAddress(request, sysUser);
    }

    /**
     * 发货地址修改
     *
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> updateShipperAddress(@RequestBody @Validated(ShipperAddressRequest.Update.class) ShipperAddressRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return shipperAddressService.updateShipperAddress(request, sysUser);
    }

    /**
     * 发货地址删除
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> deleteShipperAddress(@RequestBody @Validated CommonIdRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return shipperAddressService.deleteShipperAddress(request, sysUser);
    }

    /**
     * 门店发货地址列表
     * @param request 接口参数
     * @return 返回结果
     */
    @RequestMapping(value = "/store/list", method = RequestMethod.GET)
    public Wrapper<List<StoreShipperAddressListResponse>> storeShipperAddressList(@Valid StoreShipperAddressListRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return shipperAddressService.storeShipperAddressList(request);
    }
}
